__author__ = 'toriycn'

import subprocess
import sys

def monitor(frist_invoke = 1):
    shell_command = 'sar 1 3 | grep "^Average:"'
    result = subprocess.check_output(shell_command,shell=True)
    result = str(result.decode("utf-8"))
    print(result)
    value_dic = {}
    user,nice,system,iowait,steal,idle = [None]*6

    if sys.platform.startswith('linux'):
       user,nice,system,iowait,steal,idle =result.split()[2:]
    if sys.platform.startswith('darwin'):
        user,nice,system,idle =result.split()[1:]
    if iowait is None:
        iowait = 0
    value_dic = {
        'user':user,
        'nice':nice,
        'system':system,
        'iowait':iowait,
        'steal':steal,
        'idle':idle,
        'status':0
    }

    return value_dic


if __name__ == '__main__':
    print(monitor())